import { ElMessage } from "element-plus";

export default async (text: string) => {
    try {
        await navigator.clipboard.writeText(text);
        ElMessage.success("复制成功");
    } catch (error) {
        try {
            const input = document.createElement("input");
            input.value = text;
            input.style.position = "absolute";
            input.style.width = "10px";
            input.style.left = "-10px";
            document.body.appendChild(input);
            input.select();
            document.execCommand("copy");
            input.remove();
            ElMessage.success("复制成功");
        } catch (error) {
            ElMessage.error("复制失败");
        }
    }
};
